import React, { Component } from 'react'
import { Button, Table, Modal, Row, Col, Popconfirm, Input, Form, message } from 'antd';
import { connect } from 'react-redux';
// import { actionCreators } from './store';
import { findFailure, findFailureByNumber, repostResource, getUntrendReason, getResourceInfo, getResourceTableInfo} from '../../../api/resourceCategory/resourceCategory'
import CommonView from '../commonView'

class UnTreated extends Component {
  constructor() {
    super()
    this.state = {
      dataSource: [],
      showReason: false,
      reason: '',
      showView: false,
      paginationNo: {
        pageSize: 10,
        defaultCurrent:1,
        current:1,
      },
      columns : [
        {
          title:'报送时间',
          key:'create_time',
          dataIndex:'create_time',
        },
        {
          title: '操作',
          dataIndex: 'action',
          key: 'action',
          width: 250,
          render: (text, record) => {
            return (
              <div>
                <Button size="small" type="link" onClick={() => this.viewReason(record)}>退回说明</Button>
                <Button size="small" type="link" onClick={() => this.handleEditClick(record)} disabled={record.exec_status === '已执行'}>编辑</Button>
                <Popconfirm
                  title="确认删除?"
                  onConfirm={() => this.handleDeleteClick(record)}
                  okText="确定"
                  cancelText="取消"
                >
                  <Button size="small" type="link">
                    删除
                    </Button>
                </Popconfirm>
              </div>
            )
          }
        }
      ]
    }


  }
  handleEditClick(record) {
    console.log('edit', record)
    this.setState({
      editTitle: '编辑页面  ' + '任务名称' + record.service_name
    })

    this.setState({
      show: true
    })
  }

  viewReason = record => {
    console.log('view reason', record)
    let obj={resourceId: record.resource_id}
    getUntrendReason(obj).then(res => {
      if(res.data.metaData.code === 'success') {
        this.setState({
          showReason: true,
          reason: res.data.data
        })
      }
      console.log(res.data.data)
    })
  }

  getTaskList = () => {

  }

  getFailure = (number, page, pageSize) => {
    findFailure({pageNum: page, pageSize: pageSize, number}).then(res => {
      if(res.data.metaData.code === 'success') {
        const paginationNo = this.state.paginationNo
        paginationNo.total = res.data.data.total
        paginationNo.current = res.data.data.pageNum
        this.setState({dataSource: res.data.data.list})
      }
    })
  }
  componentWillMount() {

    console.log('this.props.baseCOlumns', this.props.baseColumns)
    this.setState({
      columns: [...this.props.baseColumns ,...this.state.columns]
    })
    this.getFailure('01010000', 1,10)
  }
  showModal = () => {
    this.setState({
      show: true
    })
  }
  handleOk = e => {
    this.setState({
      show: false
    })
  }

  handleCancel = e => {
    this.setState({
      show: false
    })
  }

  //删除配置
  handleDeleteClick(record) {
    // this.props.deleteAnalyseTask({code: code})
  }
  render() {
    const  { curRecord, columns, dataSource, showReason, reason, showView } = this.state
    return (
      <div>
          <Table
            size="small" loading={this.state.loading}
            dataSource={dataSource}
            columns={columns} bordered rowKey={record => record.taskId} 
            style={{ padding: 20 }}
            pagination={this.state.paginationNo} />
          
              {/* 编辑任务 */}
        <Modal title={this.state.editTitle}
         visible={this.state.show} width={'75%'}
         onOk={this.handleOk} onCancel={this.handleOk} closable={true}
         footer={null}
         >
        </Modal>
        <Modal title={this.state.historyLogTitle} visible={this.state.showHistoryLog} width={'80%'} onOk={this.handleLogOk} onCancel={this.handleLogOk} closable={true}>
        </Modal>
        {/* bodyStyle={{backgroundColor:'#f0f3f6',}} */}
        <Modal title='退回说明' visible={showReason} closable width={300} onCancel={e => this.setState({showReason: false})}
          bodyStyle={{backgroundColor:'#f0f3f6',}}
          footer={[<Button type="primary" size='small' onClick={e => this.setState({showReason: false})}>确定</Button>]}>
          <div style={{padding: '0px 20px 0px 20px',   margin: '24px 16px 0 16px '}}>
            <div style={{margin: 'auto', width: '100%', textAlign: 'center'}}>
              {reason}
            </div>
          </div>
        </Modal>
      </div>
    )
  }
}



const mapState = (state) => {
  // const { taskList} = state.DataAnalyseReducer;
  // const obj = {taskList}
  // console.log('质量剖析',obj)
  // return {
  //    taskList
  // }
}

const mapDispatch = (dispatch) => {
  return {
    deleteAnalyseTask(data) {
    },
    
  }
} 
export default connect(mapState, mapDispatch)(UnTreated)


